
//
//  UIView+ZFObjcSugar.m
//  Account
//
//  Created by Young on 16/8/12.
//  Copyright © 2016年 Young. All rights reserved.
//

#import "UIView+ZFObjcSugar.h"

@implementation UIView (ZFObjcSugar)

#pragma mark - Frame
- (CGPoint)zf_viewOrigin {
    return self.frame.origin;
}

- (void)setZf_viewOrigin:(CGPoint)zf_viewOrigin {
    CGRect newFrame = self.frame;
    newFrame.origin = zf_viewOrigin;
    self.frame = newFrame;
}

- (CGSize)zf_viewSize {
    return self.frame.size;
}

- (void)setZf_viewSize:(CGSize)zf_viewSize {
    CGRect newFrame = self.frame;
    newFrame.size = zf_viewSize;
    self.frame = newFrame;
}

#pragma mark - Frame Origin
- (CGFloat)zf_x {
    return self.frame.origin.x;
}

- (void)setZf_x:(CGFloat)zf_x {
    CGRect newFrame = self.frame;
    newFrame.origin.x = zf_x;
    self.frame = newFrame;
}

- (CGFloat)zf_y {
    return self.frame.origin.y;
}

- (void)setZf_y:(CGFloat)zf_y {
    CGRect newFrame = self.frame;
    newFrame.origin.y = zf_y;
    self.frame = newFrame;
}

#pragma mark - Frame Size
- (CGFloat)zf_width {
    return self.frame.size.width;
}

- (void)setZf_width:(CGFloat)zf_width {
    CGRect newFrame = self.frame;
    newFrame.size.width = zf_width;
    self.frame = newFrame;
}

- (CGFloat)zf_height {
    return self.frame.size.height;
}

- (void)setZf_height:(CGFloat)zf_height {
    CGRect newFrame = self.frame;
    newFrame.size.height = zf_height;
    self.frame = newFrame;
}

#pragma mark - 截屏
- (UIImage *)zf_capturedImage {
    
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0);
    
    UIImage *result = nil;
    if ([self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]) {
        result = UIGraphicsGetImageFromCurrentImageContext();
    }
    
    UIGraphicsEndImageContext();
    
    return result;
}

@end
